﻿//    TestGenerator - experiment with piping data into ffmpeg in "pipefmt"
//    Copyright (C) 2012  Juergen Bohl

//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.

//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.

//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
namespace TestGenerator
{
    internal enum VideoSampleType
    {
        YV12
    }

    internal class VideoFormat
    {
        private VideoSampleType videoSampleType;

        private int width;

        private int height;

        private int framerateNum;
        private int framerateDen;

        public VideoFormat(VideoSampleType type, int width, int height, int frameRateNumerator, int frameRateDenominator)
        {
            this.videoSampleType = type;
            this.width = width;
            this.height = height;
            int gcd = Gcd(frameRateNumerator, frameRateDenominator);
            this.framerateNum = frameRateNumerator / gcd;
            this.framerateDen = frameRateDenominator / gcd;
        }

        public VideoSampleType SampleType
        {
            get { return this.videoSampleType; }
        }

        public int Width
        {
            get { return this.width; }
        }

        public int Height
        {
            get { return this.height; }
        }

        public int FramerateNumerator
        {
            get { return this.framerateNum; }
        }

        public int FramerateDenominator
        {
            get { return this.framerateDen; }
        }

        /// <summary>
        /// Calculate the Greatest Common Divisor.
        /// </summary>
        /// <param name="a">The first integer.</param>
        /// <param name="b">The second integer.</param>
        /// <returns>The greatest common divisor.</returns>
        private static int Gcd(int a, int b)
        {
            while (b != 0)
            {
                int remainder = a % b;
                a = b;
                b = remainder;
            }

            return a;
        }
    }

    internal enum AudioSampleType
    {
        /// <summary> PCM coded, 16 bit signed integers in little-endian-format.  </summary>
        PCM_S16LE,

        /// <summary> PCM coded, 32 bit floats in little-endian-format.  </summary>
        PCM_F32LE
    }

    internal class AudioFormat
    {
        private AudioSampleType sampleType;

        private int channelCount;

        private int sampleRate;

        public AudioFormat(AudioSampleType type, int channelCount, int sampleRate)
        {
            this.sampleType = type;
            this.channelCount = channelCount;
            this.sampleRate = sampleRate;
        }

        public AudioSampleType SampleType
        {
            get { return this.sampleType; }
        }

        public int ChannelCount
        {
            get { return this.channelCount; }
        }

        public int SampleRate
        {
            get { return this.sampleRate; }
        }
    }
}
